<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>TurtleDB: src/ca/uqac/dim/turtledb/Engine.java Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">TurtleDB
   
   </div>
   <div id="projectbrief">A mini distributed database system</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Packages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('_engine_8java.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">src/ca/uqac/dim/turtledb/Engine.java</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_engine_8java.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*-------------------------------------------------------------------------</span>
<a name="l00002"></a>00002 <span class="comment">    Simple distributed database engine</span>
<a name="l00003"></a>00003 <span class="comment">    Copyright (C) 2012  Sylvain Hallé</span>
<a name="l00004"></a>00004 <span class="comment"></span>
<a name="l00005"></a>00005 <span class="comment">    This program is free software: you can redistribute it and/or modify</span>
<a name="l00006"></a>00006 <span class="comment">    it under the terms of the GNU General Public License as published by</span>
<a name="l00007"></a>00007 <span class="comment">    the Free Software Foundation, either version 3 of the License, or</span>
<a name="l00008"></a>00008 <span class="comment">    (at your option) any later version.</span>
<a name="l00009"></a>00009 <span class="comment"></span>
<a name="l00010"></a>00010 <span class="comment">    This program is distributed in the hope that it will be useful,</span>
<a name="l00011"></a>00011 <span class="comment">    but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00012"></a>00012 <span class="comment">    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<a name="l00013"></a>00013 <span class="comment">    GNU General Public License for more details.</span>
<a name="l00014"></a>00014 <span class="comment"></span>
<a name="l00015"></a>00015 <span class="comment">    You should have received a copy of the GNU General Public License</span>
<a name="l00016"></a>00016 <span class="comment">    along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<a name="l00017"></a>00017 <span class="comment"> -------------------------------------------------------------------------*/</span>
<a name="l00018"></a>00018 <span class="keyword">package </span>ca.uqac.dim.turtledb;
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 <span class="keyword">import</span> java.util.*;
<a name="l00021"></a>00021 <span class="keyword">import</span> java.util.Map.Entry;
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 <span class="keyword">import</span> org.w3c.dom.Document;
<a name="l00024"></a>00024 
<a name="l00025"></a>00025 <span class="keyword">import</span> ca.uqac.dim.turtledb.QueryVisitor.VisitorException;
<a name="l00026"></a>00026 
<a name="l00038"></a><a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html">00038</a> <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html">Engine</a>
<a name="l00039"></a>00039 {
<a name="l00040"></a><a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#abe4f2a3c91bb50dd8eae920fc4f70b7a">00040</a>   <span class="keyword">protected</span> Map&lt;String,Relation&gt; <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#abe4f2a3c91bb50dd8eae920fc4f70b7a">m_tables</a>;
<a name="l00041"></a>00041   
<a name="l00045"></a><a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#acd0ede62f32f128788ebece4966a09ea">00045</a>   <span class="keyword">protected</span> List&lt;Relation&gt; <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#acd0ede62f32f128788ebece4966a09ea">m_pendingQueries</a>;
<a name="l00046"></a>00046   
<a name="l00050"></a><a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a324ad5477ac8645f31483a7e4b493e21">00050</a>   <span class="keyword">protected</span> <span class="keywordtype">int</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a324ad5477ac8645f31483a7e4b493e21">m_numTuplesReceived</a>;
<a name="l00051"></a>00051   
<a name="l00055"></a><a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#ae2dbc25a1e13d2b649b58db1420a3c55">00055</a>   <span class="keyword">protected</span> String <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#ae2dbc25a1e13d2b649b58db1420a3c55">m_siteName</a>;
<a name="l00056"></a>00056   
<a name="l00060"></a><a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a2e327c6ae16bfdfd6f33a3bb2b316392">00060</a>   <span class="keyword">public</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a2e327c6ae16bfdfd6f33a3bb2b316392">Engine</a>(String name)
<a name="l00061"></a>00061   {
<a name="l00062"></a>00062     super();
<a name="l00063"></a>00063     <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#abe4f2a3c91bb50dd8eae920fc4f70b7a">m_tables</a> = <span class="keyword">new</span> HashMap&lt;String,Relation&gt;();
<a name="l00064"></a>00064     <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#acd0ede62f32f128788ebece4966a09ea">m_pendingQueries</a> = <span class="keyword">new</span> LinkedList&lt;Relation&gt;();
<a name="l00065"></a>00065     <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a324ad5477ac8645f31483a7e4b493e21">m_numTuplesReceived</a> = 0;
<a name="l00066"></a>00066     <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#ae2dbc25a1e13d2b649b58db1420a3c55">m_siteName</a> = name;
<a name="l00067"></a>00067   }
<a name="l00068"></a>00068   
<a name="l00076"></a><a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#ae0151fa00d1f1bd56f1e22a9b4e554b1">00076</a>   <span class="keyword">public</span> <span class="keywordtype">void</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#ae0151fa00d1f1bd56f1e22a9b4e554b1">putRelation</a>(String name, <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html">Relation</a> r)
<a name="l00077"></a>00077   {
<a name="l00078"></a>00078     <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#abe4f2a3c91bb50dd8eae920fc4f70b7a">m_tables</a>.put(name, r);
<a name="l00079"></a>00079   }
<a name="l00080"></a>00080   
<a name="l00085"></a><a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a69916ef536a8cc50b7963f698324b679">00085</a>   <span class="keyword">public</span> <span class="keywordtype">void</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a69916ef536a8cc50b7963f698324b679">addQuery</a>(<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html">Relation</a> query)
<a name="l00086"></a>00086   {
<a name="l00087"></a>00087     <span class="comment">// Update count of received tuples from the outside world</span>
<a name="l00088"></a>00088     <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a324ad5477ac8645f31483a7e4b493e21">m_numTuplesReceived</a> += query.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html#aa39696dd8f39129e2c02e1323c01b124">tupleCount</a>();
<a name="l00089"></a>00089     <span class="keywordflow">if</span> (query.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html#a78d7c63efc57aac8604051a03443551c">isFragment</a>())
<a name="l00090"></a>00090     {
<a name="l00091"></a>00091       assert query instanceof <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_variable_table.html">VariableTable</a>;
<a name="l00092"></a>00092       VariableTable vt = (VariableTable) query;
<a name="l00093"></a>00093       <span class="keywordflow">if</span> (vt.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_variable_table.html#a2a3a115140d8bb32a040cd7a3dbcdae0">getSite</a>().compareTo(<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#ae2dbc25a1e13d2b649b58db1420a3c55">m_siteName</a>) != 0)
<a name="l00094"></a>00094       {
<a name="l00095"></a>00095         <span class="comment">// The fragment is not destined to this site: therefore it is a query</span>
<a name="l00096"></a>00096         <span class="comment">// plan. Connect plan&#39;s leaves to any local tables...</span>
<a name="l00097"></a>00097         <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_table_link_visitor.html">TableLinkVisitor</a> tlv = <span class="keyword">new</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_table_link_visitor.html">TableLinkVisitor</a>(<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#abe4f2a3c91bb50dd8eae920fc4f70b7a">m_tables</a>);
<a name="l00098"></a>00098         <span class="keywordflow">try</span>
<a name="l00099"></a>00099         {
<a name="l00100"></a>00100           query.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html#adb708409ab8c4a428ed102c4ce850ffe">accept</a>(tlv);
<a name="l00101"></a>00101         }
<a name="l00102"></a>00102         <span class="keywordflow">catch</span> (<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_empty_query_visitor.html">EmptyQueryVisitor</a>.VisitorException e)
<a name="l00103"></a>00103         {
<a name="l00104"></a>00104           e.printStackTrace();
<a name="l00105"></a>00105         }
<a name="l00106"></a>00106         <span class="comment">// Add plan to pending queries        </span>
<a name="l00107"></a>00107         <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#acd0ede62f32f128788ebece4966a09ea">m_pendingQueries</a>.add(query);
<a name="l00108"></a>00108       }
<a name="l00109"></a>00109       <span class="keywordflow">else</span>
<a name="l00110"></a>00110       {
<a name="l00111"></a>00111         <span class="comment">// The fragment is destined to this site: iterate over pending queries and</span>
<a name="l00112"></a>00112         <span class="comment">// check if fragment can be connected to some of their leaves</span>
<a name="l00113"></a>00113         <span class="keywordflow">for</span> (<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html">Relation</a> r : <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#acd0ede62f32f128788ebece4966a09ea">m_pendingQueries</a>)
<a name="l00114"></a>00114         {
<a name="l00115"></a>00115           <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_table_link_visitor.html">TableLinkVisitor</a> tlv = <span class="keyword">new</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_table_link_visitor.html">TableLinkVisitor</a>((VariableTable) query);
<a name="l00116"></a>00116           <span class="keywordflow">try</span>
<a name="l00117"></a>00117           {
<a name="l00118"></a>00118             r.accept(tlv);
<a name="l00119"></a>00119           }
<a name="l00120"></a>00120           <span class="keywordflow">catch</span> (<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_empty_query_visitor.html">EmptyQueryVisitor</a>.VisitorException e)
<a name="l00121"></a>00121           {
<a name="l00122"></a>00122             e.printStackTrace();
<a name="l00123"></a>00123           }
<a name="l00124"></a>00124         }
<a name="l00125"></a>00125       }
<a name="l00126"></a>00126     }
<a name="l00127"></a>00127     <span class="keywordflow">else</span>
<a name="l00128"></a>00128     {
<a name="l00129"></a>00129       <span class="comment">// Not a fragment; connect plan&#39;s leaves to any local tables...</span>
<a name="l00130"></a>00130       <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_table_link_visitor.html">TableLinkVisitor</a> tlv = <span class="keyword">new</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_table_link_visitor.html">TableLinkVisitor</a>(<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#abe4f2a3c91bb50dd8eae920fc4f70b7a">m_tables</a>);
<a name="l00131"></a>00131       <span class="keywordflow">try</span>
<a name="l00132"></a>00132       {
<a name="l00133"></a>00133         query.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html#adb708409ab8c4a428ed102c4ce850ffe">accept</a>(tlv);
<a name="l00134"></a>00134       }
<a name="l00135"></a>00135       <span class="keywordflow">catch</span> (<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_empty_query_visitor.html">EmptyQueryVisitor</a>.VisitorException e)
<a name="l00136"></a>00136       {
<a name="l00137"></a>00137         e.printStackTrace();
<a name="l00138"></a>00138       }
<a name="l00139"></a>00139       <span class="comment">// Add plan to pending queries        </span>
<a name="l00140"></a>00140       <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#acd0ede62f32f128788ebece4966a09ea">m_pendingQueries</a>.add(query);
<a name="l00141"></a>00141     }
<a name="l00142"></a>00142   }
<a name="l00143"></a>00143   
<a name="l00149"></a><a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a75d87c32bedf11ceaaf4aabcaa3d4bb5">00149</a>   <span class="keyword">public</span> <span class="keywordtype">void</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a69916ef536a8cc50b7963f698324b679">addQuery</a>(Collection&lt;Relation&gt; queries)
<a name="l00150"></a>00150   {
<a name="l00151"></a>00151     <span class="keywordflow">for</span> (<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html">Relation</a> q : queries)
<a name="l00152"></a>00152       <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a69916ef536a8cc50b7963f698324b679">addQuery</a>(q);
<a name="l00153"></a>00153   }
<a name="l00154"></a>00154   
<a name="l00159"></a><a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a0875d6d4fa02325381018551d28bbdf4">00159</a>   <span class="keyword">public</span> Set&lt;Relation&gt; <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a0875d6d4fa02325381018551d28bbdf4">processPendingQueries</a>()
<a name="l00160"></a>00160   {
<a name="l00161"></a>00161     Set&lt;Relation&gt; processed = <span class="keyword">new</span> HashSet&lt;Relation&gt;();
<a name="l00162"></a>00162     Iterator&lt;Relation&gt; it = <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#acd0ede62f32f128788ebece4966a09ea">m_pendingQueries</a>.iterator();
<a name="l00163"></a>00163     <span class="keywordflow">while</span> (it.hasNext())
<a name="l00164"></a>00164     {
<a name="l00165"></a>00165       <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html">Relation</a> pq = it.next();
<a name="l00166"></a>00166       <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_ready_to_process_visitor.html">ReadyToProcessVisitor</a> rtv = <span class="keyword">new</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_ready_to_process_visitor.html">ReadyToProcessVisitor</a>();
<a name="l00167"></a>00167       <span class="keywordflow">try</span>
<a name="l00168"></a>00168       {
<a name="l00169"></a>00169         pq.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html#adb708409ab8c4a428ed102c4ce850ffe">accept</a>(rtv);
<a name="l00170"></a>00170       }
<a name="l00171"></a>00171       <span class="keywordflow">catch</span> (<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_query_visitor_1_1_visitor_exception.html">VisitorException</a> e)
<a name="l00172"></a>00172       {
<a name="l00173"></a>00173         <span class="comment">// This should not happen anyway</span>
<a name="l00174"></a>00174         e.printStackTrace();
<a name="l00175"></a>00175       }
<a name="l00176"></a>00176       <span class="keywordflow">if</span> (!rtv.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_ready_to_process_visitor.html#aef526e3918e160c434cf89099d2b751c">isReady</a>())
<a name="l00177"></a>00177         <span class="keywordflow">continue</span>;
<a name="l00178"></a>00178       <span class="comment">// Query is ready</span>
<a name="l00179"></a>00179       it.remove(); <span class="comment">// Remove from list of pending queries</span>
<a name="l00180"></a>00180       <span class="comment">// Computes the result and copies it into a new table</span>
<a name="l00181"></a>00181       <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html">Relation</a> to_add;
<a name="l00182"></a>00182       <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_table.html">Table</a> result = <span class="keyword">new</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_table.html">Table</a>();
<a name="l00183"></a>00183       result.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_table.html#a8629afcfbc2c3791cf3f94d9feacd505">copy</a>(pq);
<a name="l00184"></a>00184       to_add = result;
<a name="l00185"></a>00185       <span class="comment">// If relation is a fragment, affix the fragment&#39;s label to the computed result</span>
<a name="l00186"></a>00186       <span class="keywordflow">if</span> (pq.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html#a78d7c63efc57aac8604051a03443551c">isFragment</a>())
<a name="l00187"></a>00187       {
<a name="l00188"></a>00188         <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_variable_table.html">VariableTable</a> vt = (<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_variable_table.html">VariableTable</a>) pq;
<a name="l00189"></a>00189         <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_variable_table.html">VariableTable</a> head = <span class="keyword">new</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_variable_table.html">VariableTable</a>(vt.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_variable_table.html#a54f9a15de2f8de3ee349b9c5b7e4124e">m_name</a>, vt.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_variable_table.html#a2d43191d5c6c3f11ac98654b7bf9a098">m_site</a>);
<a name="l00190"></a>00190         head.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_unary_relation.html#a4e8c1751811a5c45c6d4ebf611146b3d">setRelation</a>(result);
<a name="l00191"></a>00191         to_add = head;
<a name="l00192"></a>00192       }
<a name="l00193"></a>00193       <span class="comment">// Put that table into list of computed results</span>
<a name="l00194"></a>00194       processed.add(to_add);
<a name="l00195"></a>00195     }
<a name="l00196"></a>00196     <span class="keywordflow">return</span> processed;
<a name="l00197"></a>00197   }
<a name="l00198"></a>00198   
<a name="l00204"></a><a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#acb1c919eba2627b81af6038737a2e693">00204</a>   <span class="keyword">public</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_query_plan.html">QueryPlan</a> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#acb1c919eba2627b81af6038737a2e693">getQueryPlan</a>(<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html">Relation</a> query)
<a name="l00205"></a>00205   {
<a name="l00206"></a>00206     <span class="comment">// TODO</span>
<a name="l00207"></a>00207     <span class="keywordflow">return</span> null;
<a name="l00208"></a>00208   }
<a name="l00209"></a>00209   
<a name="l00215"></a><a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#ae9740e5e82e1c0a27d2f776d5f94e9c5">00215</a>   <span class="keyword">public</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_table.html">Table</a> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#ae9740e5e82e1c0a27d2f776d5f94e9c5">evaluate</a>(<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html">Relation</a> query)
<a name="l00216"></a>00216   {  
<a name="l00217"></a>00217     <span class="comment">// Update count of received tuples from the outside world</span>
<a name="l00218"></a>00218     <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a324ad5477ac8645f31483a7e4b493e21">m_numTuplesReceived</a> += query.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html#aa39696dd8f39129e2c02e1323c01b124">tupleCount</a>();
<a name="l00219"></a>00219     <span class="comment">// Connect leaves to actual tables</span>
<a name="l00220"></a>00220     <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_table_link_visitor.html">TableLinkVisitor</a> tlv = <span class="keyword">new</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_table_link_visitor.html">TableLinkVisitor</a>(<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#abe4f2a3c91bb50dd8eae920fc4f70b7a">m_tables</a>);
<a name="l00221"></a>00221     <span class="keywordflow">try</span>
<a name="l00222"></a>00222     {
<a name="l00223"></a>00223       query.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html#adb708409ab8c4a428ed102c4ce850ffe">accept</a>(tlv);
<a name="l00224"></a>00224     }
<a name="l00225"></a>00225     <span class="keywordflow">catch</span> (<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_empty_query_visitor.html">EmptyQueryVisitor</a>.VisitorException e)
<a name="l00226"></a>00226     {
<a name="l00227"></a>00227       e.printStackTrace();
<a name="l00228"></a>00228     }
<a name="l00229"></a>00229     <span class="comment">// Computes the result and copies it into a new table</span>
<a name="l00230"></a>00230     <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_table.html">Table</a> out = <span class="keyword">new</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_table.html">Table</a>();
<a name="l00231"></a>00231     out.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_table.html#a8629afcfbc2c3791cf3f94d9feacd505">copy</a>(query);
<a name="l00232"></a>00232     <span class="keywordflow">return</span> out;
<a name="l00233"></a>00233   }
<a name="l00234"></a>00234   
<a name="l00240"></a><a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a313f75b83903774366501e0263c583fc">00240</a>   <span class="keyword">public</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_table.html">Table</a> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#ae9740e5e82e1c0a27d2f776d5f94e9c5">evaluate</a>(String s)
<a name="l00241"></a>00241   {
<a name="l00242"></a>00242     <span class="keywordflow">try</span>
<a name="l00243"></a>00243     {
<a name="l00244"></a>00244       <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html">Relation</a> q = <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_xml_query_parser.html">XmlQueryParser</a>.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_xml_query_parser.html#af45aba32674228c6538d7055ea6e0c6d">parse</a>(s);
<a name="l00245"></a>00245       <span class="keywordflow">return</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#ae9740e5e82e1c0a27d2f776d5f94e9c5">evaluate</a>(q);
<a name="l00246"></a>00246     }
<a name="l00247"></a>00247     <span class="keywordflow">catch</span> (<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_xml_query_parser.html">XmlQueryParser</a>.ParseException e)
<a name="l00248"></a>00248     {
<a name="l00249"></a>00249       e.printStackTrace();
<a name="l00250"></a>00250     }
<a name="l00251"></a>00251     <span class="keywordflow">return</span> null;
<a name="l00252"></a>00252   }
<a name="l00253"></a>00253   
<a name="l00254"></a><a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a5e51f3ae0cbf374ef1f964e74cb2d165">00254</a>   <span class="keyword">public</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_table.html">Table</a> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#ae9740e5e82e1c0a27d2f776d5f94e9c5">evaluate</a>(Document d)
<a name="l00255"></a>00255   {
<a name="l00256"></a>00256     <span class="keywordflow">try</span>
<a name="l00257"></a>00257     {
<a name="l00258"></a>00258       <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html">Relation</a> q = <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_xml_query_parser.html">XmlQueryParser</a>.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_xml_query_parser.html#af45aba32674228c6538d7055ea6e0c6d">parse</a>(d);
<a name="l00259"></a>00259       <span class="keywordflow">return</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#ae9740e5e82e1c0a27d2f776d5f94e9c5">evaluate</a>(q);
<a name="l00260"></a>00260     }
<a name="l00261"></a>00261     <span class="keywordflow">catch</span> (<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_xml_query_parser.html">XmlQueryParser</a>.ParseException e)
<a name="l00262"></a>00262     {
<a name="l00263"></a>00263       e.printStackTrace();
<a name="l00264"></a>00264     }
<a name="l00265"></a>00265     <span class="keywordflow">return</span> null;
<a name="l00266"></a>00266   }
<a name="l00267"></a>00267   
<a name="l00274"></a><a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#afe382772677f32c01e99491546bb92c7">00274</a>   <span class="keyword">public</span> <span class="keywordtype">int</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#afe382772677f32c01e99491546bb92c7">getStorageSize</a>()
<a name="l00275"></a>00275   {
<a name="l00276"></a>00276     <span class="keywordtype">int</span> size = 0;
<a name="l00277"></a>00277     <span class="keywordflow">for</span> (Entry&lt;String,Relation&gt; e : <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#abe4f2a3c91bb50dd8eae920fc4f70b7a">m_tables</a>.entrySet())
<a name="l00278"></a>00278     {
<a name="l00279"></a>00279       <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html">Relation</a> r = e.getValue();
<a name="l00280"></a>00280       size += r.<a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_relation.html#ad9a0a0c06639d3697952669e4c504420">getCardinality</a>();
<a name="l00281"></a>00281     }
<a name="l00282"></a>00282     <span class="keywordflow">return</span> size;
<a name="l00283"></a>00283   }
<a name="l00284"></a>00284   
<a name="l00291"></a><a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a0f1f2a11d6134baab599777810cb8ab3">00291</a>   <span class="keyword">public</span> <span class="keywordtype">int</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a0f1f2a11d6134baab599777810cb8ab3">getTuplesReceived</a>()
<a name="l00292"></a>00292   {
<a name="l00293"></a>00293     <span class="keywordflow">return</span> <a class="code" href="classca_1_1uqac_1_1dim_1_1turtledb_1_1_engine.html#a324ad5477ac8645f31483a7e4b493e21">m_numTuplesReceived</a>;
<a name="l00294"></a>00294   }
<a name="l00295"></a>00295 }
</pre></div></div><!-- contents -->
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="_engine_8java.html">Engine.java</a>      </li>

    <li class="footer">Generated on Fri Dec 7 2012 18:55:40 for TurtleDB by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.6.1 </li>
   </ul>
 </div>


</body>
</html>
